package com.cyc.basic.leecode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenyunchang
 * @title
 * @date 2021/3/30 15:17
 * @Description:
 */
public class SumTest {
    public static void main(String[] args) {
        SumTestSolution sumTestSolution = new SumTestSolution();
        int[] nums = {1, 2, 3, 4};
        int target = 5;
        int[] ints = sumTestSolution.twoSum(nums, target);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }
}
class SumTestSolution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0, n = nums.length; i < n; ++i) {
            int num = target - nums[i];
            if (map.containsKey(num)) {
                return new int[]{map.get(num), i};
            }
            map.put(nums[i], i);
        }
        return null;
    }
}